<?php
include_once '../header1.php';
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
</script>
<script type="text/javascript">
function DeleteVerification(rownum,variables)
{
	var rownum=rownum;
	var id="Verifi";
var r=confirm("Are you sure to delete this?");
if(r==true)
{
document.getElementById(id).value=variables;
}
}
</script>
<script type="text/javascript">
function GetTBox(tbox,rows)
{
	var i;
	var box="groupcolumn"+tbox;
	for(i=1;i<=rows;i++)
	{
		var tb="groupcolumn"+i;
		var b="button"+i;
		if(tb!=box)
		{
		document.getElementById(tb).value="";
		document.getElementById(b).innerHTML="";
		}
	}
	
}
</script>
<script type="text/javascript">
function GetCol(val,name,rownum)
{
	var rownum=rownum;
	var xmlhttp; 
var b="button"+rownum;
var n=val+","+rownum+","+name;
if (val=="")
  {
  document.getElementById(b).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById(b).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","butt.php?q="+n,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php

include_once ("../Login/databaseconnection.php");
if(!loggedin())
{
require_once ("../index.php");
}
   
   else
   {
   $action="";
    if(!isset($_POST['gby'])&&!isset($_POST['groupback']))
  {
	   $_SESSION['sele_groupby']="";
	   $_SESSION['back_groupby']=0;	
 $_SESSION['Column_name']="";	
$_SESSION['gvals']=""; 
}	   
	   $action="";
  if(isset($_POST['gby']))
  {
	  $action="group";
	 $crvalues=$_POST['crval'];
	 $crvalu=explode(",",$crvalues);
	 $Column=$crvalu[0];
	  $rownum=$crvalu[1];
     $pri_keys=$_POST['pri'];
	 $prikeys=explode(",",$pri_keys);
	$Census_Number=$prikeys[0];
    	 if(empty($_SESSION['sele_groupby']))
	  {
		 $_SESSION['sele_groupby']=$pri_keys.",".$Column;
	  }
	  else
	  {
		 $_SESSION['sele_groupby']=$_SESSION['sele_groupby']."_".$pri_keys.",".$Column;
	  } 
	  
$sele_groupby=explode("_",$_SESSION['sele_groupby']);

if($Column==1)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="School_Id";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",School_Id";
}
}
if($Column==2)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Congeniality";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Congeniality";
}
}
if($Column==3)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Ethinicity";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Ethinicity";
}
}
if($Column==4)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Zone";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Zone";
}
}
if($Column==5)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Division";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Division";
}
}
if($Column==6)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Province";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Province";
}
}
 if($Column==7)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="District";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",District";
}
}
if($Column==8)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Census_Number";
}
else
{
$_SESSION['Column_name']= $_SESSION['Column_name'].",Census_Number";
}
}
if($Column==9)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Name";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Name";
}
}
if($Column==10)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Principal_Name";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Principal_Name";
}
}
if($Column==11)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Status";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Status";
}
}
if($Column==12)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Type";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Type";
}
}
if($Column==13)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Grade_Range";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Grade_Range";
}
}
if($Column==14)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Medium";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Medium";
}
}
if($Column==15)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Female_Students";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Female_Students";
}
}
if($Column==16)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Male_Students";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Male_Students";
}
}
if($Column==17)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Tp_Number";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Tp_Number";
}
}
if($Column==18)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Fax_Number";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Fax_Number";
}
}	 
if($Column==19)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="E_Mail";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",E_Mail";
}
}
if($Column==20)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Web_Address";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Web_Address";
}
}
if($Column==21)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Special_Projects";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Special_Projects";
}
}
if($Column==22)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Address";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Address";
}
}
if($Column==23)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Account_Number";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Account_Number";
}
}
if($Column==24)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Last_Updated_Date";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Last_Updated_Date";
}
}
if($Column==25)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Function";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Function";
}
}
  $Column_names=explode(",", $_SESSION['Column_name']);
  $tot_cols=count($Column_names);
  $Exc_que="SELECT * FROM school WHERE Census_Number='".$Census_Number."'";
 $gro=mysql_query("SELECT * FROM school WHERE Census_Number='".$Census_Number."'");
   $number_of_rows=mysql_num_rows($gro);
if($rowgro=mysql_fetch_array($gro))
{
$Col_name= $Column_names[$tot_cols-1];
if($rowgro[$Col_name]=="")
{
$_SESSION['value_empty']="Sorry,the column value is empty";
}
else
{
if(empty($_SESSION['gvals']))
{
$_SESSION['gvals']=$rowgro[$Col_name];
}
else
{
$_SESSION['gvals']=$_SESSION['gvals'].",".$rowgro[$Col_name];
}
}
}
	}  
   if(isset($_POST['groupback']))
  {
	  $sele_groupby=explode("_",$_SESSION['sele_groupby']);
	 $_SESSION['back_groupby']=$_SESSION['back_groupby']+1;
	 
	  $gval=explode(",",$_SESSION['gvals']);
  $Column_names=explode(",",$_SESSION['Column_name']);
  $Columns="";
$Vals="";
  for($b=0;$b<count($Column_names)-1;$b++)
  { 
   if(empty($Vals))
  {
  $Vals=$gval[$b];
  }
  else
  {
  $Vals=$Vals.",".$gval[$b];
  }
   if(empty($Columns))
  {
  $Columns=$Column_names[$b];
  }
  else
  {
  $Columns=$Columns.",".$Column_names[$b];
  }
  }
  $_SESSION['gvals']=$Vals;
$_SESSION['Column_name']=$Columns;
  $gval=explode(",",$_SESSION['gvals']);
  $Column_names=explode(",",$_SESSION['Column_name']);
    if($_SESSION['Access_Type']=="Administrator")
  {
      if($_SESSION['Column_name']=="")
  {
   $res_que="SELECT * FROM school";
  }
  else
  {
   $res_que="SELECT * FROM school WHERE ";
   for($j=0;$j<count($Column_names);$j++)
  {
  $Col_name=$Column_names[$j];
   $res_que=$res_que.$Col_name."='".$gval[$j]."'";
   if($j!=(count($Column_names)-1))
  {
  $res_que=$res_que." AND ";
  }
  }
  }
    $resultgro=mysql_query($res_que);
	$Exc_que=$res_que;
   $number_of_rows=mysql_num_rows($resultgro);
    }
 if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
  {
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   }
    if($_SESSION['Column_name']=="")
  {
   $res_que="SELECT * FROM school WHERE School_Id='".$Own_School_Id."'";
  }
  else
  {
   $res_que="SELECT * FROM school WHERE ";
   for($j=0;$j<count($Column_names);$j++)
  {
  $Col_name=$Column_names[$j];
    $res_que=$res_que.$Col_name."='".$gval[$j]."'";
   if($j!=(count($Column_names)-1))
  {
  $res_que=$res_que." AND ";
  }
  if($j==(count($Column_names)-1))
  {
  $res_que=$res_que." AND School_Id='".$Own_School_Id."'";
  }
  }
  }
     $resultgro=mysql_query($res_que);
	$Exc_que=$res_que;
   $number_of_rows=mysql_num_rows($resultgro);
     }
  }
    if(isset($_POST['dele']))
  {
   $action="delete";
   }
   ?>
<?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<br/>
<?php
if($action=="delete")
{
$dvari=$_POST['Verifi'];
if($dvari!="")
{
$vari=explode(",",$dvari);
$Census_Number=$vari['0'];
}
if($dvari!="")
{
if($_SESSION['Access_Type']=="Administrator")
{
 $result=mysql_query("SELECT * FROM school WHERE Census_Number='$Census_Number'");
 $resultexa=mysql_query("SELECT * FROM exam WHERE School_Id='$Own_School_Id'");
	$resultpro=mysql_query("SELECT * FROM programmes WHERE School_Id='$Own_School_Id'");
	$resultcom=mysql_query("SELECT * FROM school competition School_Id='$Own_School_Id'");
$Accessed_By=$_SESSION['NIC_Number'];
   date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
	if($result)
	{
   if($row=mysql_fetch_array($result))
   {
   $Principal_Name=$row['Principal_Name'];
$Zone=$row['Zone'];
$Census_Number=$row['Census_Number'];
$Medium=$row['Medium'];
$Female_Students=$row['Female_Students'];
$Male_Students=$row['Male_Students'];
$Special_Pro=$row['Special_Projects'];
$Medium=$row['Medium'];
$Account_Number=$row['Account_Number'];
$School_Id=$row['School_Id'];
$Name=$row['Name'];
$Address=$row['Address'];
$Division=$row['Division'];
$District=$row['District'];
$Province=$row['Province'];
$Status=$row['Status'];
$Type=$row['Type'];
$Grade_Range=$row['Grade_Range'];
$Tp_Number=$row['Tp_Number'];
$Fax_Number=$row['Fax_Number'];
$E_Mail=$row['E_Mail'];
$Web_Address=$row['Web_Address'];
$Congeniality=$row['Congeniality'];
$Function=$row['Function'];
$Ethinicity=$row['Ethinicity'];
$Last_Updated_Date=$row['Last_Updated_Date'];  
   }
      if($resultcom)
   {
  while($rowcom=mysql_fetch_array($resultcom))
   {
   if(empty($Competition_Id))
   {
   $Competition_Id=$rowcom['Competition_Id'];
   }
   else
   {
   $Competition_Id=$Competition_Id.",".$rowcom['Competition_Id'];
   }
   if(empty($No_Of_Students))
   {
   $No_Of_Students=$rowcom['No_Of_Students'];
   }
   else
   {
   $No_Of_Students=$No_Of_Students.",".$rowcom['No_Of_Students'];
   }
   if(empty($No_Of_Teachers))
   {
   $No_Of_Teachers=$rowcom['No_Of_Teachers'];
   }
   else
   {
   $No_Of_Teachers=$No_Of_Teachers.",".$rowcom['No_Of_Teachers'];
   }
   if(empty($Result))
   {
   $Result=$rowcom['Result'];
   }
   else
   {
   $Result=$Result.",".$rowcom['Result'];
   }
   if(empty($Date))
   {
   $Date=$rowcom['Date'];
   }
   else
   {
   $Date=$Date.",".$rowcom['Date'];
   }
   if(empty($Scope))
   {
   $Scope=$rowcom['Scope'];
   }
   else
   {
   $Scope=$Scope.",".$rowcom['Scope'];
   }
   if(empty($Winner))
   {
   $Winner=$rowcom['Winner'];
   }
   else
   {
   $Winner=$Winner.",".$rowcom['Winner'];
   } 
}
}
if($resultpro)
   {
 while($rowpro=mysql_fetch_array($resultpro))
   {
 if(empty($Required_Teachers))
   {
   $Required_Teachers=$rowpro['Required_Teachers'];
   }
   else
   {
   $Required_Teachers=$Required_Teachers.",".$rowpro['Required_Teachers'];
   }
   if(empty($Pro_Id))
   {
  $Pro_Id=$rowpro['Programme_Id'];
   }
   else
   {
   $Pro_Id=$Pro_Id.",".$rowpro['Programme_Id'];
   }
    if(empty($Grade))
   {
  $Grade=$rowpro['Grade'];
   }
   else
   {
   $Grade=$Grade.",".$rowpro['Grade'];
   }
   if(empty($Year))
   {
   $Year=$rowpro['Year'];
   }
   else
   {
   $Year=$Year.",".$rowpro['Year'];
   }
   if(empty($No_F_Stu))
   {
   $No_F_Stu=$rowpro['No_Of_Female_Students'];
   }
   else
   {
   $No_F_Stu=$No_F_Stu.",".$rowpro['No_Of_Female_Students'];
   }
    if(empty($No_M_Stu))
   {
   $No_M_Stu=$rowpro['No_Of_Male_Students'];
   }
   else
   {
   $No_M_Stu=$No_M_Stu.",".$rowpro['No_Of_Male_Students'];
   }
   if(empty($No_Tra_tea))
   {
   $No_Tra_tea=$rowpro['Teachers_In_Training'];
   }
   else
   {
   $No_Tra_tea=$No_Tra_tea.",".$rowpro['Teachers_In_Training'];
   }
   if(empty($Tra_tea))
   {
   $Tra_tea=$Tra_tea.",".$rowpro['Trained_Teachers'];
   }
   else
   {
   $Tra_tea=$Tra_tea.",".$rowpro['Trained_Teachers'];
   }
   if(empty($Avai_Book))
   {
   $Avai_Book=$rowpro['Availability_Books'];
   }
   else
   {
   $Avai_Book=$Avai_Book.",".$rowpro['Availability_Books'];
   }
   if(empty($Avai_Tea_Gui))
   {
   $Avai_Tea_Gui=$rowpro['Availability_Tguides'];
   }
   else
   {
   $Avai_Tea_Gui=$Avai_Tea_Gui.",".$rowpro['Availability_Tguides'];
   }
}
}
if($resultexa)
   {
while($rowexa=mysql_fetch_array($resultexa))
   {
   if(empty($Exam_Name))
   {
   $Exam_Name=$rowexa['Exam_Name'];
   }
   else
   {
   $Exam_Name=$Exam_Name.",".$rowexa['Exam_Name'];
   }
   if(empty($Year))
   {
   $Year=$rowexa['Year'];
   }
   else
   {
   $Year=$Year.",".$rowexa['Year'];
   }
   if(empty($No_Of_Sat_Students))
   {
   $No_Of_Sat_Students=$rowexa['No_Of_Sat_Students'];
   }
   else
   {
   $No_Of_Sat_Students=$No_Of_Sat_Students.",".$rowexa['No_Of_Sat_Students'];
   }
   if(empty($No_Of_Passed_Students))
   {
   $No_Of_Passed_Students=$rowexa['No_Of_Passed_Students'];
   }
   else
   {
   $No_Of_Passed_Students=$No_Of_Passed_Students.",".$rowexa['No_Of_Passed_Students'];
   }

	}
}
$sql=mysql_query("INSERT INTO deleted_school(Competition_Id,No_Of_Students,No_Of_Teachers,Result,Date,Scope,Winner,Required_Teachers,Grade,Programme_Id,Year,No_Of_Students,Teachers_In_Training,Trained_Teachers,Availability_Books,Availability_Tguides,Congeniality,Function,Ethinicity,School_Id,Zone,Division,Province,District,Census_Number,Name,Principal_Name,Status,Type,Grade_Range,Medium,Female_Students,Male_Students,Tp_Number,Fax_Number,E_Mail,Web_Address,Special_Projects,Address,Account_Number,Deleted_date,Accessed_By,Last_Updated_Date,Exam_Name,Exa_Year,No_Of_Sat_Students,No_Of_Passed_Students) VALUES('$Competition_Id','$No_Of_Students','$No_Of_Teachers','$Result','$Date','$Scope','$Winner','$Required_Teachers','$Grade','$Pro_Id','$Year','$Sch_Id','$No_Stu','$No_Tra_tea','$Tra_tea','$Avai_Book','$Avai_Tea_Gui','$Congeniality','$Function','$Ethinicity','$School_Id','$Zone','$Division','$Province','$District','$Census_Number','$Name','$Principal_Name','$Status','$Type','$Grade_Range','$Medium','$Female_Students','$Male_Students','$Tp_Number','$Fax_Number','$E_Mail','$Web_Address','$Special_Pro','$Address','$Account_Number','$t_d','$Accessed_By','$Last_Updated_Date','$Exam_Name','$Exa_Year','$No_Of_Sat_Students','$No_Of_Passed_Students')");
if($sql){
   $del=mysql_query("DELETE FROM school WHERE Census_Number='$Census_Number'");
	
	if(mysql_affected_rows()!=0)
  {
$_SESSION['del']="This record is successfully deleted!";
if($resultexa)
   {
		  while($rowtra=mysql_fetch_array($resultexa))
		 {
		  $delexa=mysql_query("DELETE FROM exam WHERE School_Id='$School_Id'");
		 }
		 }
		 	 if($resultpro)
   {
		 while($rowres=mysql_fetch_array($resultpro))
		 {
	  	$delpro=mysql_query("DELETE FROM programmes WHERE School_Id='$School_Id'");
		 }
		 }
		  	 if($resultcom)
   {
		 while($rowc=mysql_fetch_array($resultcom))
		 {
	  $delcom=mysql_query("DELETE FROM competition WHERE School_Id='$School_Id'");
		 }
		 }		 
 if(mysql_num_rows(mysql_query("SELECT * FROM school competition School_Id='$School_Id'"))!=0)
	  {
$_SESSION['del']=$_SESSION['del']." ,unable to delete this record from competition!";
  }  
  if(mysql_num_rows(mysql_query("SELECT * FROM exam WHERE School_Id='$School_Id'"))!=0)
	  {
 $_SESSION['del']=$_SESSION['del']." ,unable to delete this record from exam!";
   }
 if(mysql_num_rows(mysql_query("SELECT * FROM programmes WHERE School_Id='$School_Id'"))!=0)
	  {
 $_SESSION['del']=$_SESSION['del']." ,unable to delete this record from programmes!";
   }
  }

  if(mysql_affected_rows()==0)
  {
 $_SESSION['del']="Sorry unable to delete this record!";
 mysql_query("DELETE FROM deleted_school WHERE Census_Number='$Census_Number' AND Deleted_Date='$t_d'");

  }
  }
    if(!$sql)
{
 $_SESSION['del']="Sorry unable to delete this record!";
 }
}
}
}
}
echo '<form  action="#" method="POST">';
echo "<input type='hidden' size='1' id='Verifi' name='Verifi'/>";
echo '<br/>';
 if($_GET['action']=="edit"&&$action!="delete"&&$action!="group"&&!isset($_POST['groupback'])&&$_SESSION['Access_Type']!="Teacher")
	{
	$Census_Number=$_GET['Census_Number'];
$result=mysql_query("SELECT * FROM school WHERE Census_Number='$Census_Number'");
if($result)
   {
$qucol="SHOW COLUMNS FROM school";
$resultcol=mysql_query($qucol);
$totcol=mysql_num_rows($resultcol);
while($rowcolu=mysql_fetch_row($resultcol))
{
if(empty($colnamearray))
{
$colnamearray=$rowcolu[0];
}
else
{
$colnamearray=$colnamearray.",".$rowcolu[0];
}
}
	$cnamearray=explode(",",$colnamearray);
     if(!isset($_POST['Go']))
	 {
	 echo '<div style="width:500px; height:410px; overflow-Y:scroll; ">';
	 echo '<table width="480" class="tablefontv">';
	if($rowsch=mysql_fetch_array($result))
  {
 $cnamearray=explode(',',$colnamearray);
    for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
	    $valu=$rowsch[$val];
		if($val!="Last_Updated_Date")
		{
    echo '<tr bgcolor="#6AB5FF">';
        echo '<th width="200" height="29" scope="row" bgcolor="#3399CC">';
		echo $th_cname.":";
		echo '</th>';
        echo '<td width="144">';
		if($th_cname=="Special Projects")
	{
$All_Special_Projects=="";
$OLPC="";
$Interactive_Whiteboard="";
$Isuru="";
$Navodaya="";
$E_village="";
$Tho_School_Dev="";
$Child_friendly_school="";
$all_S_P=mysql_query("SELECT DISTINCT(Special_Projects) FROM school");
while($r_sp=mysql_fetch_array($all_S_P))
{
$sp_exists="";
$each_sp=explode(",",$r_sp['Special_Projects']);
$All_SProjects=explode(",",$All_Special_Projects);
for($spr=0;$spr<count($each_sp);$spr++)
{
if($each_sp[$spr]!="")
{
if(substr($each_sp[$spr],0,6)=="other_")
{
$each_sp[$spr]=substr($each_sp[$spr],6);
}
if($each_sp[$spr]=="OLPC")
{
$OLPC="exists";
}
else if($each_sp[$spr]=="Interactive Whiteboard")
{
$Interactive_Whiteboard="exists";
}
else if($each_sp[$spr]=="Isuru")
{
$Isuru="exists";
}
else if($each_sp[$spr]=="Navodaya")
{
$Navodaya="exists";
}
else if($each_sp[$spr]=="E-village")
{
$E_village="exists";
}
else if($each_sp[$spr]=="1000 School Dev")
{
$Tho_School_Dev="exists";
}
else if($each_sp[$spr]=="Child friendly school")
{
$Child_friendly_school="exists";
}
for($s=0;$s<count($All_SProjects);$s++)
{
if($each_sp[$spr]==$All_SProjects[$s])
{
$sp_exists="yes";
break;
}
}
if($sp_exists!="yes")
{
if(empty($All_Special_Projects))
{
$All_Special_Projects=$each_sp[$spr];
}
else
{
$All_Special_Projects=$All_Special_Projects.",".$each_sp[$spr];
}
}
}
}
}
if($OLPC!="exists")
{
if(empty($All_Special_Projects))
{
$All_Special_Projects="OLPC";
}
else
{
$All_Special_Projects=$All_Special_Projects.",OLPC";
}
  }
  if($Interactive_Whiteboard!="exists")
{
if(empty($All_Special_Projects))
{
$All_Special_Projects="Interactive Whiteboard";
}
else
{
$All_Special_Projects=$All_Special_Projects.",Interactive Whiteboard";
}
   }
   if($Isuru!="exists")
{
if(empty($All_Special_Projects))
{
$All_Special_Projects="Isuru";
}
else
{
$All_Special_Projects=$All_Special_Projects.",Isuru";
}
   }
     if($Navodaya!="exists")
{
if(empty($All_Special_Projects))
{
$All_Special_Projects="Navodaya";
}
else
{
$All_Special_Projects=$All_Special_Projects.",Navodaya";
}
   }
     if($E_village!="exists")
{
if(empty($All_Special_Projects))
{
$All_Special_Projects="E-village";
}
else
{
$All_Special_Projects=$All_Special_Projects.",E-village";
}
   }
     if($Tho_School_Dev!="exists")
{
if(empty($All_Special_Projects))
{
$All_Special_Projects="1000 School Dev";
}
else
{
$All_Special_Projects=$All_Special_Projects.",1000 School Dev";
}
   }
   if($Child_friendly_school!="exists")
{
if(empty($All_Special_Projects))
{
$All_Special_Projects="Child friendly school";
}
else
{
$All_Special_Projects=$All_Special_Projects.",Child friendly school";
}
}
$All_Spe_Projects=explode(",",$All_Special_Projects);
$other="";
echo '<div style="width:180px; height:150px; overflow-Y:scroll; ">';
if($valu!="")
{
$S_Proje= explode(",",$valu);
for($s=0;$s<count($All_Spe_Projects);$s++)
{
$S_Proj="";
for($i=0;$i<count($S_Proje);$i++)
{
if($S_Proje[$i]==$All_Spe_Projects[$s])
{
$S_Proj="yes";
}
}
if($S_Proj=="yes")
{
echo "<input type='checkbox' name='Special_Projects[]' value='$All_Spe_Projects[$s]' checked='checked'/>";
  echo $All_Spe_Projects[$s];
    echo '<br/>';
  }
  else if($S_Proj=="")
  {
echo "<input type='checkbox' name='Special_Projects[]' value='$All_Spe_Projects[$s]'/>";
  echo $All_Spe_Projects[$s];
    echo '<br/>';
  }
else if(substr($All_Spe_Projects[$s],0,6)=="other_")
  {
  $other="exists";
    $sp=substr($All_Spe_Projects[$s],6);
	if($sp!="")
	{
echo "<input type='checkbox' name='Special_Projects[]' value='Others(P1.specify)' checked='checked'/>";
echo "Others";
  echo '<br/>';
  }
  else
  {
echo "<input type='checkbox' name='Special_Projects[]' value='Others(P1.specify)'/>";
echo "Others";
  echo '<br/>';
  }
?>
<textarea name='Special_Projects_Others'><?php echo $sp." "; ?></textarea>
<?php
}
}
if($other!="exists")
{
echo "<input type='checkbox' name='Special_Projects[]' value='Others(P1.specify)'/>";
echo "Others";
  echo '<br/>';
 ?>
<textarea name='Special_Projects_Others'></textarea>
<?php
}
}
else
{
for($sp=0;$sp<count($All_Spe_Projects);$sp++)
{
echo "<input type='checkbox' name='Special_Projects[]' value='$All_Spe_Projects[$sp]'/>";
echo "$All_Spe_Projects[$sp]";
echo '<br/>';
}
echo "<input type='checkbox' name='Special_Projects[]' value='Others(P1.specify)'/>";
echo "Others:";
  echo '<br/>';
echo "<textarea name='Special_Projects_Others'></textarea>";
}
	}
	else if($th_cname=="Type")
	{
	if($valu=="1AB")
	 {
       echo '<input type="radio" name="Type" value="1AB" id="Type_0" checked="checked" />';
       echo "1AB";
	 }
      
	   else
	   {
		   echo '<input type="radio" name="Type" value="1AB" id="Type_0" />';
       echo "1AB";} 
	    echo '<br />';
        if($valu=="1C")
	 {
         echo '<input type="radio" name="Type" value="1C" id="Type_1" checked="checked" />';
         echo "1C";
	 }
	 else
	 {
		  echo '<input type="radio" name="Type" value="1C" id="Type_1" />';
         echo "1C";
	 }
       echo '<br />';
       
	     if($valu=="2")
	 {
         echo '<input type="radio" name="Type" value="2" id="Type_2" checked="checked" />';
         echo "2";
	 } else
	 {
		  echo '<input type="radio" name="Type" value="2" id="Type_2" />';
         echo "2";
	 }
       echo '<br />';
      if($valu=="3")
	  { 
         echo '<input type="radio" name="Type" value="3" id="Type_3" checked="checked" />';
         echo "3";
	  }
		  else
	 {
		 echo '<input type="radio" name="Type" value="3" id="Type_3" />';
         echo "3";
	 }
	}
	else if($th_cname=="Grade Range")
	{
	 if($valu=="1-5")
	  {
        echo '<input type="radio" name="Grade_Range" value="1-5" id="Grade_Range_0" checked="checked" />';
        echo "1-5";
	  }
	  else
	  {
		  echo '<input type="radio" name="Grade_Range" value="1-5" id="Grade_Range_0" />';
        echo "1-5";
	  }
	   echo '<br />';
	  if($valu=="1-11")
	  {
       
        echo '<input type="radio" name="Grade_Range" value="1-11" id="Grade_Range_3" checked="checked" />';
          echo "1-11";
		  }
	  else
	  {
		  echo '<input type="radio" name="Grade_Range" value="1-11" id="Grade_Range_3" />';
          echo "1-11";
	  }
        echo '<br />';
		if($valu=="1-13")
		{
       echo '<input type="radio" name="Grade_Range" value="1-13" id="Grade_Range_4" checked="checked" />';
          echo "1-13";
        }
	  else
	  {
		   echo '<input type="radio" name="Grade_Range" value="1-13" id="Grade_Range_4" />';
          echo "1-13";
	  }
        echo '<br />';
       
       if($valu=="6-11")
	   {   echo '<input type="radio" name="Grade_Range" value="6-11" id="Grade_Range_1" checked="checked" />';
          echo "6-11";
		  }
	  else
	  {
		  echo '<input type="radio" name="Grade_Range" value="6-11" id="Grade_Range_1" />';
          echo "6-11";
	  }
		 echo '<br />';
       if($valu=="6-13")
	   {
          echo '<input type="radio" name="Grade_Range" value="6-13" id="Grade_Range_2" checked="checked" />';
          echo "6-13";
		  }
	  else
	  {
		  echo '<input type="radio" name="Grade_Range" value="6-13" id="Grade_Range_2" />';
          echo "6-13";
	  }
		echo '<br />';
		if($valu=="Others")
		{
        echo '<input type="radio" name="Grade_Range" value="Others" id="Grade_Range_5" checked="checked" />';
          echo "Others";
		}
	  else
	  {
		  echo '<input type="radio" name="Grade_Range" value="Others" id="Grade_Range_5" />';
          echo "Others";
	  }
	}
	else if($th_cname=="Medium")
	{
	if($valu=="Tamil")
	  {
        echo '<input type="radio" name="Medium" value="Tamil" id="Medium_0" checked="checked" />';
       echo "Tamil";
	   }else
	   {
		   echo '<input type="radio" name="Medium" value="Tamil" id="Medium_0" />';
       echo "Tamil";
	   }
        echo '<br />';
		if($valu=="English")
	  {
        echo '<input type="radio" name="Medium" value="English" id="Medium_1" checked="checked" />';
          echo "English";
	  }else
	  {
		  echo '<input type="radio" name="Medium" value="English" id="Medium_1" />';
          echo "English";
	  }
        echo '<br />';
		if($valu=="Mix(Tamil & English)")
	  {
        echo '<input type="radio" name="Medium" value="Mix(Tamil &amp; English)" id="Medium_2" checked="checked" />';
          echo "Mix(Tamil &amp; English)";
	  }
		  else
		  {
			  echo '<input type="radio" name="Medium" value="Mix(Tamil &amp; English)" id="Medium_2" />';
          echo "Mix(Tamil &amp; English)";
		  }
        echo '<br />';
		if($valu=="Sinhala")
	  {
        echo '<input type="radio" name="Medium" value="Sinhala" id="Medium_3" checked="checked" />';
          echo "Sinhala";
	  }else
	  {
		   echo '<input type="radio" name="Medium" value="Sinhala" id="Medium_3" />';
          echo "Sinhala";
	  }
        echo '<br />';
		if($valu=="Mix(Tamil &amp; Sinhala)")
	  {
       echo '<input type="radio" name="Medium" value="Mix(Tamil &amp; Sinhala)" id="Medium_4" checked="checked" />';
          echo "Mix(Tamil &amp; Sinhala)";
	  }else
	  {
		  echo '<input type="radio" name="Medium" value="Mix(Tamil &amp; Sinhala)" id="Medium_4" />';
          echo "Mix(Tamil &amp; Sinhala)";
	  }
        echo '<br />';
		if($valu=="Mix(Tamil,English &amp; Sinhala)")
	  {
        echo '<input type="radio" name="Medium" value="Mix(Tamil,English &amp; Sinhala)" id="Medium_5" checked="checked" />';
         echo "Mix(Tamil,English &amp; Sinhala)";
	  }else
	  {
		   echo '<input type="radio" name="Medium" value="Mix(Tamil,English &amp; Sinhala)" id="Medium_5" />';
         echo "Mix(Tamil,English &amp; Sinhala)";
	  }
	}
	else if($th_cname=="Status")
	{
	 if($valu=="National")
	  {
	    echo '<input type="radio" name="Status" value="National" id="Status_0" checked="checked" />';
	   echo "National";
	  }
	  else
	  {
		  echo '<input type="radio" name="Status" value="National" id="Status_0" />';
	   echo "National";
	  }
        echo '<br />';
        if($valu=="Provincial")
		{
          echo '<input type="radio" name="Status" value="Provincial" id="Status_1" checked="checked" />';
          echo "Provincial";
  }
  else
  {
	   echo '<input type="radio" name="Status" value="Provincial" id="Status_1" />';
          echo "Provincial";
  }
   echo '<br />';
    if($valu=="Private")
		{
          echo '<input type="radio" name="Status" value="Private" id="Status_2" checked="checked" />';
          echo "Private";
  }
  else
  {
	   echo '<input type="radio" name="Status" value="Private" id="Status_2" />';
          echo "Private";
  }
	}
	else if($th_cname=="Function")
	{
	?>
<select name="Function" id="Function">
        <?php
		 if(isset($valu))
	  {
	 echo '<option value="'.$valu.'">'.$valu.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  	  $func=mysql_query("SELECT DISTINCT(Function) FROM school");
	  
  while($row=mysql_fetch_array($func))
  {
	 $Fun=$row['Function'];
if($Fun!=$valu)
{
	  echo '<option value="'.$Fun.'">'.$Fun.'</option>';
}
  }
 
	  ?>
      </select></br><label><font color="red">or</font> New function:&nbsp;&nbsp;&nbsp;</label>
	  <?php
	  if($New_Function!="")
	  {
	  echo "<input type='text' name='New_Function' value='$New_Function'/>";
	  }
	  else
	  {
	  echo "<input type='text' name='New_Function'/>";
	  }
	}
	else if($th_cname=="Ethinicity")
	{
	?>
<select name="Ethinicity" id="Ethinicity">
        <?php
		 if(isset($valu))
	  {
	 echo '<option value="'.$valu.'">'.$valu.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  	  $eth=mysql_query("SELECT DISTINCT(Ethinicity) FROM school");
	  
  while($row=mysql_fetch_array($eth))
  {
	 $Ethni=$row['Ethinicity'];
if($Ethni!=$valu)
{
	  echo '<option value="'.$Ethni.'">'.$Ethni.'</option>';
}
  }
 
	  ?>
      </select></br><label><font color="red">or</font> New ethinicity:&nbsp;&nbsp;&nbsp;</label>
	  <?php
	  if($New_Ethinicity!="")
	  {
	  echo "<input type='text' name='New_Ethinicity' value='$New_Ethinicity'/>";
	  }
	  else
	  {
	  echo "<input type='text' name='New_Ethinicity'/>";
	  }
	}
	else if($th_cname=="Congeniality")
	{
	?>
	<select name="Congeniality" id="Congeniality">
        <?php
		 if(isset($valu))
	  {
	 echo '<option value="'.$valu.'">'.$valu.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  	  $con=mysql_query("SELECT DISTINCT(Congeniality) FROM school");
	  
  while($row=mysql_fetch_array($con))
  {
	 $Cong=$row['Congeniality'];
if($Cong!=$valu)
{
	  echo '<option value="'.$Cong.'">'.$Cong.'</option>';
}
  } 
	  ?>
      </select></br><label><font color="red">or</font> New congeniality:&nbsp;&nbsp;&nbsp;</label>
	  <?php
	  if($New_Congeniality!="")
	  {
	  echo "<input type='text' name='New_Congeniality' value='$New_Congeniality'/>";
	  }
	  else
	  {
	  echo "<input type='text' name='New_Congeniality'/>";
	  }
	}
	else
	{
		echo "<input type='text' name='$val' value='$valu' size='30'>";
		}
		echo '</td>';
      echo '</tr>';
	}
	}
}	 
	 echo '</table>';
	 echo '</div>';
	  echo '<br/>';
	   echo '<input name="Go" align="middle" type="submit" value="Go" class="gobutton"/>';	
	   }
	   if(isset($_POST['Go']))
	   {
 $Congeniality=$_POST['Congeniality'];
 $New_Congeniality=$_POST['New_Congeniality'];
 $Function=$_POST['Function'];
 $New_Function=$_POST['New_Function'];
 $Ethinicity=$_POST['Ethinicity'];
 $New_Ethinicity=$_POST['New_Ethinicity'];
	   $Principal_Name=$_POST['Principal_Name'];
	$Census_Number1=$_POST['Census_Number'];
   $School_Id=$_POST['School_Id'];
   $Zone=$_POST['Zone'];
 $Division=$_POST['Division'];
   $Province=$_POST['Province'];
  $District=$_POST['District'];
$Name=$_POST['Name'];
 $Status=$_POST['Status'];
$Type=$_POST['Type'];
  $Grade_Range=$_POST['Grade_Range'];
   $Medium=$_POST['Medium'];
 $Female_Students=$_POST['Female_Students'];
  $Male_Students=$_POST['Male_Students'];
 $Tp_Number=$_POST['Tp_Number'];
  $Fax_Number=$_POST['Fax_Number'];
  $E_Mail=$_POST['E_Mail'];
  $Web_Address=$_POST['Web_Address'];
    $Address=$_POST['Address'];
 $Account_Number=$_POST['Account_Number'];
	date_default_timezone_set("Europe/Paris");
    $t_d=date("Y/m/d");
	$Special_Projects=$_POST['Special_Projects'];
  $Speci_Proje="";
  $Special_Projects_other=$_POST['Special_Projects_other'];
$Special_Pro="";
for($i=0;$i<sizeof($Special_Projects);$i++)
  {
  if($i==0)
  {
  if($Special_Projects[$i]=="Others(P1.specify)")
  {
  $Speci_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $Special_Pro="other_";
  $_SESSION['up']="Please type the other special projects!";
  }
  else
  {
  $Special_Pro="other_".$spe_other;
  }
  }
  else
  {
  $Special_Pro=$Special_Projects[0];
  }
  }
  else
  {
  if($Special_Projects[$i]=="Others(P1.specify)")
  {
  $Speci_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $Special_Pro=$Special_Pro.",other_";
  $_SESSION['up']="Please type the other special projects!";
  }
  else
  {
  $Special_Pro=$Special_Pro.",other_".$spe_other;
  }
  }
  else
  {
	$Special_Pro=$Special_Pro.",".$Special_Projects[$i];
	}
	}
	}
if(($New_Congeniality!=""||$Congeniality!="Select One")&&($New_Function!=""||$Function!="Select One")&&($New_Ethinicity!=""||$Ethinicity!="Select One")&&$Principal_Name!=""&&$Census_Number1!=""&&$School_Id!=""&&$Zone!=""&&$Division!=""&&$Province!=""&&$District!=""&&$Name!=""&&$Status!=""&&$Type!=""&&$Grade_Range!=""&&$Medium!=""&&$Female_Students!=""&&$Male_Students!=""&&$Address!="")
  {
  if($New_Ethinicity!="")
	{
	$Ethinicity=$New_Ethinicity;
	}
	if($New_Congeniality!="")
	{
	$Congeniality=$New_Congeniality;
	}
	if($New_Function!="")
	{
	$Function=$New_Function;
	}
	if($Speci_Proje=="yes")
  {
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
   if($spe_other!="")
  {
 $up=mysql_query("UPDATE school SET Congeniality='$Congeniality',Function='$Function',Ethinicity='$Ethinicity',Principal_Name='$Principal_Name',Census_Number='$Census_Number1',School_Id='$School_Id',Zone='$Zone',Division='$Division',Province='$Province',District='$District',Name='$Name',Status='$Status',Type='$Type',Grade_Range='$Grade_Range',Medium='$Medium',Female_Students='$Female_Students',Male_Students='$Male_Students',Tp_Number='$Tp_Number',Fax_Number='$Fax_Number',E_Mail='$E_Mail',Web_Address='$Web_Address',Special_Projects='$Special_Pro',Address='$Address',Account_Number='$Account_Number',Last_Updated_Date='$t_d' WHERE Census_Number='$Census_Number'");
unset($_SESSION['Census_Number']);
 if(!$up)
	   {
	   $_SESSION['up']="Sorry unable to edit this please try again!";
	   }
  }
  else
  {
   $_SESSION['up']="Please specify other project of this school!";
  }
  }
  else
  {
  $up=mysql_query("UPDATE school SET Congeniality='$Congeniality',Function='$Function',Ethinicity='$Ethinicity',Principal_Name='$Principal_Name',Census_Number='$Census_Number1',School_Id='$School_Id',Zone='$Zone',Division='$Division',Province='$Province',District='$District',Name='$Name',Status='$Status',Type='$Type',Grade_Range='$Grade_Range',Medium='$Medium',Female_Students='$Female_Students',Male_Students='$Male_Students',Tp_Number='$Tp_Number',Fax_Number='$Fax_Number',E_Mail='$E_Mail',Web_Address='$Web_Address',Special_Projects='$Special_Pro',Address='$Address',Account_Number='$Account_Number' WHERE Census_Number='$Census_Number'");
unset($_SESSION['Census_Number']);
 if(!$up)
	   {
	   $_SESSION['up']="Sorry unable to edit this please try again!";
	   }
  }
  }
	   if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	$T_NIC_Number=$_GET['T_NIC_Number'];
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $result=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
$Exc_que="SELECT * FROM school WHERE School_Id='$Own_School_Id'";
   $number_of_rows=mysql_num_rows($result);
  }
  }
	else if($_SESSION['Access_Type']=="Administrator")
	{
	   	   $result=mysql_query("SELECT * FROM school");
$Exc_que="SELECT * FROM school";
   $number_of_rows=mysql_num_rows($result);
		   }
if(mysql_num_rows($result)!=0)
   {
   $rnum=0;
if(mysql_num_rows($result)>10)
  {
  echo '<div style="width:115%; height:500px; overflow-x:scroll; overflow-y:scroll;">';
  }
  else
  {
echo '<div style="width:115%; overflow-x:scroll;">';
}
  echo '<table width="2400" border="1" class="tablefontv">';
  	if($result)
  {
echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
    for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
         echo '<td>';
			$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
		echo '</td>';
    }
		
		echo '<td>Column No</td>';
	echo '</tr>';
}

  while($row=mysql_fetch_array($result))
  {
	  $rnum=$rnum+1;  
$s=$row['Census_Number'];
$name=$s;
?>
</form>
   <tr bgcolor="#999999">
   <?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	?>
<td width="39"><a href='?action=edit&Census_Number=<?php echo $s; ?>'><img src="../images/edit.png"/></a></td>
	<?php 
	}
	if($_SESSION['Access_Type']=="Administrator")
	{
	?>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
            echo '<td>';
		echo $valu;
		echo '</td>'; 
	}
	?>
	<td width="90">
    <?php
	 if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
	   $resultte=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
$Exc_que="SELECT * FROM school WHERE School_Id='$Own_School_Id'";
   $number_of_rows=mysql_num_rows($resultte);
	   if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
  }
	}
	else if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM school");
$Exc_que="SELECT * FROM school";
   $number_of_rows=mysql_num_rows($resultte);
  $n=mysql_num_rows($resultte);
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
    <?php
  echo '</tr>';
  }
  
   echo "</table>";
   echo '</div>';
     $Column_names=explode(",",$_SESSION['Column_name']);
   if(count($Column_names)>0&&$_SESSION['Column_name']!="")
  {
   ?>
   <br/>
   <form action="#"/>
   <input type="submit" name="groupback" class="groupback" value=""/></form>
   <?php
   }
  echo "</form>";
}
	   }
	}
	}
		else
	{
	if(isset($_POST['groupback']))
  {
     $rnum=0;
	if($resultgro)
	 {	  
$qucol="SHOW COLUMNS FROM school";
$resultcol=mysql_query($qucol);
$totcol=mysql_num_rows($resultcol);
while($rowcolu=mysql_fetch_row($resultcol))
{
if(empty($colnamearray))
{
$colnamearray=$rowcolu[0];
}
else
{
$colnamearray=$colnamearray.",".$rowcolu[0];
}
}
if(mysql_num_rows($resultgro)>10)
  {
  echo '<div style="width:115%; height:500px; overflow-x:scroll; overflow-y:scroll;">';
  }
  else
  {
echo '<div style="width:115%; overflow-x:scroll;">';
}
  echo '<table width="2400" border="1" class="tablefontv">';
  echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
        echo '<td>';
			$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
while($row=mysql_fetch_array($resultgro))
  {$rnum=$rnum+1;
    $s=$row['Census_Number'];
$name=$s;
?>
<tr bgcolor="#999999"><form action='#' method='post'>
<?php
   	if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	?>
<td width="39"><a href='?action=edit&Census_Number=<?php echo $s; ?>'><img src="../images/edit.png"/></a></td>
	<?php 
	}
	if($_SESSION['Access_Type']=="Administrator")
	{
	?>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
	$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
  echo '<td>';
		echo $valu;
		echo '</td>';
	}
	?>
	<td width="90">
	<?php
	if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM school");
$Exc_que="SELECT * FROM school";
   $number_of_rows=mysql_num_rows($resultte);
  $n=mysql_num_rows($resultte);
	}
	else if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	 $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
     $resultte=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
$Exc_que="SELECT * FROM school WHERE School_Id='$Own_School_Id'";
   $number_of_rows=mysql_num_rows($resultte);
	 if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
	}
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
    <?php
  echo '</tr>';
  }
  }
   echo "</table>";
   echo '</div>';
   $Column_names=explode(",",$_SESSION['Column_name']);
   if(count($Column_names)>0&&$_SESSION['Column_name']!="")
  {
    ?>
   <br/>   
   <form action="#"/>
   <input type="submit" name="groupback" class="groupback" value=""/></form>
   <?php
   }
   ?>
   </form> 
   <?php
   }
   if(!isset($_POST['groupback']))
  {
	  if($_SESSION['Access_Type']=="Administrator")
{
$result=mysql_query("SELECT * FROM school");
$Exc_que="SELECT * FROM school";
   $number_of_rows=mysql_num_rows($result);
}
 else if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	 $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $result=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
$Exc_que="SELECT * FROM school WHERE School_Id='$Own_School_Id'";
   $number_of_rows=mysql_num_rows($result);
   }
   }
if($result)
   {
    if(mysql_num_rows($result)==0)
   {
   $_SESSION['errornorow']="Sorry there is no result to view!";
   }
   if(mysql_num_rows($result)>0)
   {
   $rnum=0;
$qucol="SHOW COLUMNS FROM school";
$resultcol=mysql_query($qucol);
$totcol=mysql_num_rows($resultcol);
while($rowcolu=mysql_fetch_row($resultcol))
{
if(empty($colnamearray))
{
$colnamearray=$rowcolu[0];
}
else
{
$colnamearray=$colnamearray.",".$rowcolu[0];
}
}
if($action!="group")
  {
  if(mysql_num_rows($result)>10)
  {
  echo '<div style="width:115%; height:500px; overflow-x:scroll; overflow-y:scroll;">';
  }
  else
  {
  echo '<div style="width:115%; overflow-x:scroll;">';
  }
  echo '<table width="2300" border="1" class="tablefontv">';
  echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	 $val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
  echo '<td>';
		$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
  while($row=mysql_fetch_array($result))
  {
	  $rnum=$rnum+1;
    
$s=$row['Census_Number'];
$delVerification="delVerification".$rnum;
$name=$s;
?>
<tr bgcolor="#999999"><?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	?>
<td width="39">
<a href='?action=edit&Census_Number=<?php echo $s; ?>'><img src="../images/edit.png"/></a></td>
	<?php 
	}
	if($_SESSION['Access_Type']=="Administrator")
	{
	?>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
	$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
		$valu=$row[$val];
            echo '<td>';
		echo $valu;
		echo '</td>';
}
	?>
	<td width="159"><?php
	 if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	 $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $resultte=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
  }
	}
	else if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM school");
  $n=mysql_num_rows($resultte);
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
   <?php
  echo '</tr>';
  }
  }
   if($action=="group")
  {
  $l_val=count($Column_names)-1;
  	$gval=explode(",",$_SESSION['gvals']);
	$Column_names=explode(",",$_SESSION['Column_name']);
    $gval=explode(",",$_SESSION['gvals']);
  if($_SESSION['Access_Type']=="Administrator")
  {  
      $res_que="SELECT * FROM school WHERE ";
   for($j=0;$j<count($Column_names);$j++)
  {
  $Col_name=$Column_names[$j];
     $res_que=$res_que.$Col_name."='".$gval[$j]."'";
   if($j!=(count($Column_names)-1))
  {
  $res_que=$res_que." AND ";
  }
  }
	 $resultgro=mysql_query($res_que);
	$Exc_que=$res_que;
   $number_of_rows=mysql_num_rows($resultgro);
  }
 if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
  {
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   }
      $res_que="SELECT * FROM school WHERE ";
   for($j=0;$j<count($Column_names);$j++)
  {
  $Col_name=$Column_names[$j];
   
  $res_que=$res_que.$Col_name."='".$gval[$j]."'";
  
  if($j!=(count($Column_names)-1))
  {
  $res_que=$res_que." AND ";
  }
  if($j==(count($Column_names)-1))
  {
  $res_que=$res_que." AND School_Id='".$Own_School_Id."'";
  }
  }
   $resultgro=mysql_query($res_que);
	$Exc_que=$res_que;
   $number_of_rows=mysql_num_rows($resultgro);
 }
 if(mysql_num_rows($resultgro)>=10)
   {
 echo '<div style="width:115%; height:410px; overflow-Y:scroll; overflow-X:scroll;">';
 }
 else
 {
 echo '<div style="width:115%; overflow-X:scroll;">';
 }
  echo '<table width="2400" border="1" class="tablefontv">';
  if($gval[$l_val]!="")
  {
echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	 $val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
  echo '<td>';
		$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
  $Column_names=explode(",",$_SESSION['Column_name']);
    $gval=explode(",",$_SESSION['gvals']);
	if($_SESSION['Column_name']!="")
  {
  
   while($row=mysql_fetch_array($resultgro))
  {
  $rnum=$rnum+1;    
$s=$row['Census_Number'];
$name=$s;
?>
<tr bgcolor="#999999"><?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	?>
<td width="39">
<a href='?action=edit&Census_Number=<?php echo $s; ?>'><img src="../images/edit.png"/></a></td>
	<?php 
	}
	if($_SESSION['Access_Type']=="Administrator")
	{
	?>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
	$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
		$valu=$row[$val];
 echo '<td>';
		echo $valu;
		echo '</td>';
	}
	?>
	<td width="90">
	<?php
	 if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
	{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
	   $resultte=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
	}
	}
	else
	{
		$resultte=mysql_query("SELECT * FROM school");
$n=mysql_num_rows($resultte);
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
    <?php
  echo '</tr>';
  }
  }
  }
  else
  {
echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	 $val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
  echo '<td>';
		$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
  while($row=mysql_fetch_array($result))
  {
	  $rnum=$rnum+1;
    
$s=$row['Census_Number'];
$delVerification="delVerification".$rnum;
$name=$s;
?>
<tr bgcolor="#999999"><?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	?>
<td width="39">
<a href='?action=edit&Census_Number=<?php echo $s; ?>'><img src="../images/edit.png"/></a></td>
	<?php 
	}
	if($_SESSION['Access_Type']=="Administrator")
	{
	?>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
	$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
		$valu=$row[$val];
            echo '<td>';
		echo $valu;
		echo '</td>';
   	}
	?>
	<td width="159"><?php
	 if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	 $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $resultte=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
 if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
  }
	}
	else if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM school");
$n=mysql_num_rows($resultte);
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
   <?php
  echo '</tr>';
  }
  }
  }
   echo "</table>";
   echo '</div>';
   $Column_names=explode(",",$_SESSION['Column_name']);
   if(count($Column_names)>0&&$_SESSION['Column_name']!="")
  {
   ?>
   <br/>
   <form action="#"/>
   <input type="submit" name="groupback" class="groupback" value=""/></form>
   <?php
   }
   echo "</form>";
}
}
 else
	   {
	   $_SESSION['errornorow']="Sorry there is no result to view!";
	   }
	   }
  }
  if($_GET['action']!="edit"&&$action!="delete")
  {
   if($number_of_rows>0)
   {
$Exc_quer=str_replace("'","@",$Exc_que);
echo "<form action='../exportreport.php' method='post'><input type='submit' name='ToExcel' class='print' value=''/><input type='hidden' value='$Exc_quer' name='query'/><input type='hidden' value='school' name='Exc_table_name'/></form>";
  }
  }
  ?>
<font class="err">
<?php
 if(isset($_SESSION['errornotallo']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornotallo'];
unset($_SESSION['errornotallo']);
}
if(isset($_SESSION['errornorow']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornorow'];
unset($_SESSION['errornorow']);
}
	if(isset($_SESSION['value_empty']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['value_empty'];
unset($_SESSION['value_empty']);
}

if(isset($_SESSION['groupbyempty']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['groupbyempty'];
unset($_SESSION['groupbyempty']);
}
	if(isset($_POST['Go']))
	 {
	if(isset($_SESSION['up']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['up'];
unset($_SESSION['up']);
}
}
if($action=="delete")
{
	if(isset($_SESSION['del']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['del'];
unset($_SESSION['del']);
}
}
	?>
	</font>
	  </div>
  </div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">SCHOOLS</h2>
            </div>
            <?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
}
?>

</body>
</html>